﻿using ProjectScheduling_web.model;
using SqlSugar;

namespace ProjectScheduling_web.dao
{
    public class MemberDao : BaseDao<Member>
    {
        public readonly static MemberDao Base = new();
        public List<IdName> AllNames()
        {
            //return Db.Queryable<Member>().Select((m) => new IdName(m.Id, m.Name ?? "")).ToList();
            return Db.Queryable<Member>().Select((m) => new IdName
            {
                Id = m.Id,
                Name = m.Name ?? ""
            }).ToList();
        }
        public List<IdName> SearchName(int orgId = 0, string key = "")
        {
            return Db.Queryable<Member>().Where(it=>(orgId==0 || it.OrgId == orgId) && (string.IsNullOrEmpty(key) || (it.Name != null && it.Name.Contains(key))))
                .Select(it => new IdName { Id = it.Id, Name = it.Name ?? "" })
                .Take(20)
                .ToList();
        }
    }
}
